package com.tools.scanner.ui.dialog

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import androidx.appcompat.app.AlertDialog
import com.airbnb.lottie.LottieAnimationView
import com.tools.scanner.R

class LoadingDialog(context: Context) : AlertDialog(context) {

    private var animView: LottieAnimationView? = null

    init {
        Log.e("yangyangyang", "111111111")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_loading)
        setCancelable(false)
        Log.e("yangyangyang", "2222222222")

        findViewById<LottieAnimationView>(R.id.lottieAnimationView)?.let { lottieAnimationView ->
            animView = lottieAnimationView
            lottieAnimationView.playAnimation()
            setOnDismissListener {
                lottieAnimationView.pauseAnimation()
            }
        }

        setOnShowListener {
            animView?.playAnimation()
        }

        setOnDismissListener {
            animView?.cancelAnimation()
        }
    }

    override fun show() {
        super.show()
        window?.let {
            it.setBackgroundDrawable(ColorDrawable())
            it.setGravity(Gravity.CENTER)
        }
    }
}